<script >
/**
 * 一个通知提示组件
 */
export default {
    props: {
    },
    created() { },
    watch: {
        show(val) {
            this.timer2 && clearTimeout(this.timer2)
            this.timer && clearTimeout(this.timer)
            if (val) {
                this.hide = false
                this.timer = setTimeout(() => {
                    this.timer = null
                    this.show = false
                    this.title = ""
                    this.content = ""
                    this.then && this.then()
                }, this.showTime)
            } else {
                this.timer2 = setTimeout(() => {
                    this.hide = true
                }, 400)
            }
        }
    },

    data() {
        return {
            title: "",
            content: "",
            timer: null,
            show: false,
            timer: null,
            timer2: null,
            then: null,
            showTime: 2000,
            hide: true
        }
    },
    methods: {
    }
}
</script>

<template>
    <view v-show="show">
        <view :class="{ toast: true, hide: hide, notShow: !show }">
            {{ title }}
            <view class="content">
                {{ content }}
            </view>
        </view>
        <view  class="mask">
        </view>
    </view>
</template>

<style scoped>
.toast {
    width: 50vw;
    height: 40vw;
    font-size: 4vw;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 30;
    padding: 3vw;
    padding-top: 10%;
    text-align: center;
    box-sizing: border-box;
    background: #f0efef;
    border: 1px solid #acaaaa;
    border-radius: 20px;
    transition: .4s;
    font-family: 'Microsoft YaHei';
    font-style: normal;
    font-weight: 400;
}

.content {
    margin-top: 7%;
    height: 50%;
    font-weight: 100;
}

.hide {
    display: none;
}

.notShow {
    opacity: 0;
}
</style>
